package com.tuo51.foudation.utils;


import lombok.extern.slf4j.Slf4j;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

/**
 * *******************************
 * Created by Ron.
 * form com.tuo51
 * on 2017/12/8
 * *******************************
 */
@Slf4j
public class PushUtils {

    public static final String EVALUATE_TEMPLATE = "%s老师为您的宝宝%s提交了一份能力发展测评, 园区专家会在七天内根据测评结果补充更详细的评估建议并发送给您, 请耐心等待.";


    public static boolean push(String url, String feedId) {
        try {
            String str = String.format(url + "api/v1/feed/push/%s", feedId);
            log.info("str:[{}]", str);
            String s = HttpClientUtil.sendGetJson(str);
            log.info("push success! result:[{}], feedsId:[{}]", s, feedId);
        } catch (IOException e) {
            log.error("push error: feedsId:[{}]", feedId);
            return false;
        }
        return true;
    }

    public static String pushJson(String url, String feedId) {
        try {
            log.info(String.format(url + "api/v1/feed/push/%s", feedId));
            String s = HttpClientUtil.sendGetJson(String.format(url + "api/v1/feed/push/%s", feedId));
            log.info("push success! result:[{}], feedsId:[{}]", s, feedId);
            return s;
        } catch (IOException e) {
            log.error("push error: feedsId:[{}]", feedId);
            return null;
        }
    }

    public static String pushApi(String url, String childrenId, String title, String alert, String body, boolean isPro) {
        try {
            url += "api/v1/push";
            log.info(url);
            Map params = new HashMap();
            params.put("id", childrenId);
            params.put("title", title);
            params.put("alert", alert);
            params.put("body", body);
            params.put("prd", isPro);
            log.info("params [{}]:", params);
            String s = HttpClientUtil.sendPost(url, params);
            log.info("response str[{}]:", s);
            log.info("push success! childrenId:[{}]", childrenId);
            return s;
        } catch (IOException e) {
            log.error("push error: childrenId:[{}]", childrenId);
            return null;
        }
    }

    public static void main(String[] args) {
        pushApi("https://s.mattbaby.com/", "2c92818e6005bfe4016007166aa402fd", "测试", "测试", null, false);
    }
}
